import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import {
	httpClient
} from './utils/api.js'
import {
	Theme
} from './common/js/common.js'
import store from './store/index.js'
import VueI18n from 'vue-i18n'

Vue.use(VueI18n);

const i18n = new VueI18n({
	locale: uni.getStorageSync('locale').locale ? uni.getStorageSync('locale').locale : 'zh-CN', //初始化,保证刷新页面也保留
	// 加载语言文件的内容
	messages: {
		'zh-CN': require('./locales/zh-CN.js').lang,
		'en': require('./locales/en.js').lang
	}
})

Vue.config.productionTip = false
Vue.prototype.$store = store
Vue.prototype.$get = httpClient.Get
Vue.prototype.$post = httpClient.Post
Vue.prototype.$theme = Theme
Vue.prototype._i18n = i18n

import {
	mapGetters
} from 'vuex';

Vue.mixin({
	computed: {
		...mapGetters(['theme', 'locale'])
	},
	methods: {
		toggleAppTheme(theme) {
			this.$store.commit('TOGGLE_APP_THEME', theme);
		},
		toggleAppLocale(locale) {
			this.$store.commit('TOGGLE_APP_LOCALE', locale);
		}
	}
})

App.mpType = 'app'
const app = new Vue({
	store,
	i18n,
	...App,
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
